package com.learn.springcloud.dubbo.controller;

import com.learn.springcloud.dubbo.api.service.TestService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: 胡伟
 * @Date: 2020/11/20 10:59
 * @Description:
 */
@RestController
public class TestApiController {
    @DubboReference
    private TestService testService;
    @Resource
    private KafkaTemplate<String,Object> kafkaTemplate;
    @GetMapping("/sayHello")
    public String sayHello(){
       return  testService.sayHello();
    }
    @GetMapping("/getName")
    public String getName(){
        return testService.getName();
    }
    @GetMapping("/test")
    public String test1(){
        return  "hello world";
    }
    @GetMapping("/getRedissionCache/{key}")
    public String getRedissionCache(@PathVariable("key") String key){
        return testService.getRedissionCache(key);
    }
    @GetMapping("/getJedisCache/{key}")
    public String getJedisCache(@PathVariable("key") String key){
        return testService.getJedisCache(key);
    }
    @GetMapping("/createMsg/{message}")
    public String createMsg(@PathVariable("message")String message) throws Exception{
        ListenableFuture listenableFuture = kafkaTemplate.send("huwei",message);
        return listenableFuture.get().toString();
    }
}
